﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using QuanLyChoVay.Bussiness;

namespace QuanLyChoVay
{
    public partial class Form1 : Form
    {
        private int quyen = -1;
        public Form1()
        {
            InitializeComponent();
            Form1_Load();
            //MessageBox.Show("Quyen = " + quyen);
        }
        //public void setQuyen(int quyen)
        //{
           // this.quyen = quyen;
        //}

        public void Form1_Load(object sender, EventArgs e)
        {
            if (quyen == 0)
            {
                llbldangnhapkh.Enabled = false;
                llbldangky.Enabled = false;
                llbldangkyvay.Enabled = false;
                llbltrogiup.Enabled = true;
                llblquanlynv.Enabled = true;
                llblquanlydmv.Enabled = true;
                llbldangnhapnv.Enabled = true;
                llblquanlyhdv.Enabled = false;
                llblquanlykh.Enabled = false;
                llblquanlykhtn.Enabled = false;
                //groupBox6.Enabled = false;
                //groupBox4.Enabled = false;
                //groupBox5.Enabled = true;
            }
            if (quyen == 1)
            {
                //groupBox6.Enabled = false;
                //groupBox4.Enabled = true;
                //groupBox5.Enabled = false;
                llbldangnhapkh.Enabled = false;
                llbldangky.Enabled = false;
                llbldangkyvay.Enabled = false;
                llbltrogiup.Enabled = false;
                llblquanlynv.Enabled = false;
                llblquanlydmv.Enabled = false;
                llbldangnhapnv.Enabled = true;
                llblquanlyhdv.Enabled = true;
                llblquanlykh.Enabled = true;
                llblquanlykhtn.Enabled = true;
            }
            if (quyen == 2)
            {
                //groupBox6.Enabled = true;
                //groupBox4.Enabled = false;
                //groupBox5.Enabled = false;
                llbldangnhapkh.Enabled = true;
                llbldangky.Enabled = true;
                llbldangkyvay.Enabled = true;
                llbltrogiup.Enabled = false;
                llblquanlynv.Enabled = false;
                llblquanlydmv.Enabled = false;
                llbldangnhapnv.Enabled = false;
                llblquanlyhdv.Enabled = false;
                llblquanlykh.Enabled = false;
                llblquanlykhtn.Enabled = false;
            }
            else
            {
                llbldangnhapkh.Enabled = true;
                llbldangky.Enabled = true;
                llbldangkyvay.Enabled = false;
                llbltrogiup.Enabled = false;
                llblquanlynv.Enabled = false;
                llblquanlydmv.Enabled = false;
                llbldangnhapnv.Enabled = true;
                llblquanlyhdv.Enabled = false;
                llblquanlykh.Enabled = false;
                llblquanlykhtn.Enabled = false;
            }
        }
        public void setQuyen(int quyen)
        {
            this.quyen = quyen;
        }
        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide(); // hide sau do phai show laij de show laij thi can them con tro quan ly no dc gui sang Dang nhap, de tu dan gnhap goij no show tro laij,  = ko no se hide forever
            DangNhapKhachHang dnkh = new DangNhapKhachHang();
            dnkh.setPointForm1(this); //truyen this sang fom nhap de luc  an di con co' cai' ma goi no show tro laij
            dnkh.ShowDialog();
            quyen = dnkh.getquyen(); // neu co cai nay thi ben kia ko can set quyen nua cung dc
            showHang(); //tai thoi diem nay quyen =2 va no se thuc thi an ham nay ko an dc :))
            //Form1_Load();
            //phep gan nay ko goi toi ham an muon goi toi ham an thi:
            lbltrangthai.Text =dnkh.gettendn();
        }
        public void showHang()
        {
            llbldangnhapkh.Enabled = true;
            llbldangky.Enabled = true;
            llbldangkyvay.Enabled = true;
            llbltrogiup.Enabled = false;
            llblquanlynv.Enabled = false;
            llblquanlydmv.Enabled = false;
            llbldangnhapnv.Enabled = false;
            llblquanlyhdv.Enabled = false;
            llblquanlykh.Enabled = false;
            llblquanlykhtn.Enabled = false;

        }
        private void llbldangky_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            KhachHangDangKy khdk = new KhachHangDangKy();
            khdk.ShowDialog();
        }

        private void llbldangkyvay_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SendData sd = new SendData();
            sd.Tendangnhap = lbltrangthai.Text;
            DangKyVay dkv = new DangKyVay(sd);
            //dkv.Tendnkhachhang = lbltrangthai.Text;
            dkv.ShowDialog();
            
        }

        private void llblquanlynv_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            QuanLyNhanVien qlnv = new QuanLyNhanVien();
            qlnv.ShowDialog();
        }

        private void llbldangnhapnv_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide();
            NhanVienDangNhap nvdn = new NhanVienDangNhap();
            nvdn.setPointForm1(this);
            nvdn.ShowDialog();
            quyen = nvdn.getquyen();
            //Form1_Load();
            if (quyen == 0)
            {
                llbldangnhapkh.Enabled = false;
                llbldangky.Enabled = false;
                llbldangkyvay.Enabled = false;
                llbltrogiup.Enabled = true;
                llblquanlynv.Enabled = true;
                llblquanlydmv.Enabled = true;
                llbldangnhapnv.Enabled = true;
                llblquanlyhdv.Enabled = false;
                llblquanlykh.Enabled = false;
                llblquanlykhtn.Enabled = false;
                //groupBox6.Enabled = false;
                //groupBox4.Enabled = false;
                //groupBox5.Enabled = true;
            }
            if (quyen == 1)
            {
                //groupBox6.Enabled = false;
                //groupBox4.Enabled = true;
                //groupBox5.Enabled = false;
                llbldangnhapkh.Enabled = false;
                llbldangky.Enabled = false;
                llbldangkyvay.Enabled = false;
                llbltrogiup.Enabled = false;
                llblquanlynv.Enabled = false;
                llblquanlydmv.Enabled = false;
                llbldangnhapnv.Enabled = true;
                llblquanlyhdv.Enabled = true;
                llblquanlykh.Enabled = true;
                llblquanlykhtn.Enabled = true;
            }
            lbltrangthai.Text =nvdn.gettendn();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("quyen = "+quyen);
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Form1_Load()
        {

        }
    }
}
